<%@ page import="admin.Connectmysql" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %><%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2025/6/14
  Time: 21:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    String oldPwd = request.getParameter("oldPassword");
    String newPwd = request.getParameter("newPassword");
    int id = (Integer) session.getAttribute("adminId");
    Connectmysql cmysql = new Connectmysql(
            "jdbc:mysql://localhost:3306/exam1",
            "root",
            "root",
            "com.mysql.cj.jdbc.Driver");
    try {
        if(cmysql.open()){

            ResultSet rst= cmysql.executeSql(
                    "SELECT id, name FROM admin WHERE id = ? AND passwd = ?;",
                    new Object[]{id, oldPwd}
            );
            if(rst.next()){
                cmysql.executeSqlUpdate("UPDATE admin SET passwd = ? where id = ?",new Object[]{newPwd, id});


                //response.sendRedirect("admin.jsp");
            }else{
                // 登录失败，返回错误信息
                request.setAttribute("error", "密码错误");
                //request.getRequestDispatcher("index.jsp").forward(request, response);
            }



//



            rst.close();
        }
    } catch (ClassNotFoundException f) {
        f.printStackTrace();
    } catch (SQLException throwables) {
        throwables.printStackTrace();
    }



    response.getWriter().write("密码修改请求已接收");
%>
<P>
    <%=oldPwd+newPwd%>
</P>
</body>
<script>

</script>
</html>
